/**
 * Copyright 2009 Sergio Bossa
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package com.googlecode.actorom.impl.remote;

import com.googlecode.actorom.Address;
import java.io.Serializable;
import net.jcip.annotations.Immutable;

/**
 * {@link com.googlecode.actorom.Address} implementation to use in a {@link RemoteTopology}.
 *
 * @author Sergio Bossa
 */
@Immutable
public class RemoteAddress implements Address, Serializable {

    private static final long serialVersionUID = 12345678901L;

    private static final String SEPARATOR = ":";

    private final String host;
    private final int port;
    private final String id;
    private final String address;

    public RemoteAddress(String host, int port, String id) {
        this.host = host;
        this.port = port;
        this.id = id;
        this.address = host + SEPARATOR + port + SEPARATOR + id;
    }

    public String getHost() {
        return host;
    }

    public int getPort() {
        return port;
    }

    public String getId() {
        return id;
    }

    public String getAddress() {
        return address;
    }

    @Override
    public int hashCode() {
        return address.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj != null && obj instanceof RemoteAddress) {
            RemoteAddress other = (RemoteAddress) obj;
            return address.equals(other.address);
        } else {
            return false;
        }
    }

    @Override
    public String toString() {
        return address.toString();
    }
}
